import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);


//保存所有组件的公共数据
const state =sessionStorage.getItem('state') ? JSON.parse(sessionStorage.getItem('state')): {
  user:{
    name:''
  }
};

const getters = {
  getUser(state){
    return state.user;
  }
};

const mutations = {
  updateUser(state, user){
    state.user = user;
  }
};

const actions = {
  asyncUpdateUser(context,user){
    context.commit('updateUser',user);
  }
};


export default new Vuex.Store({
  state,
  getters,
  mutations,
  actions
});
